Conditions | 1 |
Paths | 1 |
Total Lines | 81 |
Code Lines | 55 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var table_methods = { |
||
3 | Draw: { |
||
4 | Section: function(tableContainer, dt, tSection){ |
||
5 | var section = tSection === "tfoot" ? "tfoot" : "tbody"; |
||
6 | var tSec = document.getElementById(tableContainer) |
||
7 | .getElementsByTagName(section)[0]; |
||
8 | Clear(tSec, this.helper.IePrior(9)); |
||
9 | for(var i = 0; i < dt.length; i++){ |
||
10 | var row = dt[i]; |
||
11 | var tRow = document.createElement("tr"); |
||
12 | Row(row, tRow); |
||
13 | tSec.appendChild(tRow); |
||
14 | if(section === "tfoot"){ |
||
15 | this.helper.ProcessPaginationLinks(tSec); |
||
16 | } |
||
17 | } |
||
18 | function Clear(tSection, iePrior9){ |
||
19 | if(iePrior9){ |
||
20 | if(tSection.firstChild){ |
||
21 | while(tSection.firstChild){ |
||
22 | tSection.removeChild(tSection.firstChild); |
||
23 | } |
||
24 | } |
||
25 | }else{ |
||
26 | tSection.innerHTML = ""; |
||
27 | } |
||
28 | } |
||
29 | function Row(row, tRow){ |
||
30 | for(var cell in row){ |
||
1 ignored issue
–
show
|
|||
31 | var tCell = document.createElement("td"); |
||
32 | if(typeof row[cell] === "string" || |
||
33 | typeof row[cell] === "number" |
||
34 | ){ |
||
35 | tCell.innerHTML = row[cell]; |
||
36 | }else if(typeof row[cell] === "object"){ |
||
37 | RowCellFromObject(row, cell, tCell); |
||
38 | } |
||
39 | tRow.appendChild(tCell); |
||
40 | } |
||
41 | } |
||
42 | function RowCellFromObject(row, cell, tCell){ |
||
43 | for(var attr in row[cell]){ |
||
1 ignored issue
–
show
|
|||
44 | if(typeof row[cell][attr] === "string"){ |
||
45 | tCell.innerHTML = row[cell][attr]; |
||
46 | }else if(typeof row[cell][attr] === "object"){ |
||
47 | for(var v in row[cell][attr]){ |
||
1 ignored issue
–
show
|
|||
48 | tCell.setAttribute(v, row[cell][attr][v]); |
||
49 | } |
||
50 | } |
||
51 | } |
||
52 | } |
||
53 | }, |
||
54 | Run: function(tableContainer, d, instance){ |
||
55 | |||
56 | this.Section.call(instance, tableContainer, d.body); |
||
57 | this.Section.call(instance, tableContainer, d.footer, "tfoot"); |
||
58 | if(instance.rq !== null){ |
||
59 | var hover = document.getElementById(instance.rq.tableId) |
||
60 | .getElementsByTagName("th")[instance.rq.colNo].lang; |
||
61 | if(hover){ |
||
62 | instance.helper.ColumnHover(tableContainer, instance.rq.colNo); |
||
63 | } |
||
64 | } |
||
65 | } |
||
66 | }, |
||
67 | Export: function(lnk, eType){ |
||
68 | var tableId = this.helper.GetParent(lnk, "table").getAttribute("id"); |
||
69 | var rq = this.helper.BuildRequest.call(this, tableId); |
||
70 | rq.exportType = ["CSV", "Excel"].indexOf(eType) >= 0 ? |
||
71 | eType : |
||
72 | "csv"; |
||
73 | window.open(this.helper.RequestToUrl(rq)); |
||
74 | return false; |
||
75 | }, |
||
76 | Filter: { |
||
77 | Run: function(field){ |
||
78 | var tableId = this.Filter.GetTableId(field); |
||
79 | if(tableId !== null){ |
||
80 | /*var exRq = this.rq;*/ |
||
81 | var rq = this.helper.BuildRequest.call(this, tableId); |
||
82 | this.rq = rq; |
||
83 | this.LoadData.Run(this); |
||
84 | //@todo exRq match not work |
||
197 |
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: